﻿using System.Collections.Generic;

namespace Tomato.Allure
{
	internal class WindowsImpl : Tomato.Allure.IWindows
	{
		private EnvDTE80.Windows2 m_instance;

		public int Count
		{
			get { return m_instance.Count; }
		}

		public Tomato.Allure.IWindow this[ int index ]
		{
			get
			{
				EnvDTE.Window window = m_instance.Item( index );
				if( window != null )
				{
					return new WindowImpl( window );
				}

				return null;
			}
		}

		public Tomato.Allure.IWindow this[ string windowName ]
		{
			get
			{
				EnvDTE.Window window = m_instance.Item( windowName );
				if( window != null )
				{
					return new WindowImpl( window );
				}

				return null;
			}
		}

		public WindowsImpl( EnvDTE.Windows instance )
		{
			m_instance = ( EnvDTE80.Windows2 )( instance );
		}

		public IEnumerator<Tomato.Allure.IWindow> GetEnumerator()
		{
			for( int i = 1 ; i <= m_instance.Count ; ++i )
			{
				EnvDTE.Window window = m_instance.Item( i );
				if( window != null )
				{
					yield return new WindowImpl( window );
				}
				else
				{
					yield return null;
				}
			}
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
}
